// pages/parking/parking.js
let request = require("../../utils/request")

Page({

  /**
   * 页面的初始数据
   */
  data: {
    barHeight: wx.getMenuButtonBoundingClientRect().bottom,
    infoDialog: false,
    infoText: '',
    shopParkTicketList: [],
    shopParkTicketSetList: [],
    content: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   // 获取商户停车券
   this.getShopParkTicketList() 
   // 获取已配置商户停车券
   this.getShopParkTicketSet() 
  },
  /**
 * 获取商户停车券
 */
  getShopParkTicketList() {
    request.http(
      '/shop/shop-park-ticket/get-by-shop-id', 'GET', {shopId: wx.getStorageSync('shopId')}
    ).then(res => {
      console.log('商户停车券信息：', res)
      let shopParkTicketList = res.data.data
      this.setData({
        shopParkTicketList: shopParkTicketList
      })
    })
  },
    /**
 * 获取已配置商户停车券
 */
getShopParkTicketSet() {
  request.http(
    '/shop/park-ticket-set/list', 'GET', {shopId: wx.getStorageSync('shopId')}
  ).then(res => {
    console.log('已配置商户停车券信息：', res)
    this.setData({ shopParkTicketSetList: res.data.data })
  })
},
  /**
   * 查看详情
   */
  showInfo(e) {
    this.setData({ content: e.currentTarget.dataset.content, infoDialog: true })
  },
  /**
   * 配置停车券
   */
  setPatkTicket(e){
    let parkTicket = e.currentTarget.dataset.parkTicket
    if(parkTicket.unsettledQuantity > 0){
      wx.navigateTo({ url: '/pages/park-ticket/set-patk-ticket/setPatkTicket?ticketId=' + parkTicket.id })
    } else {
      wx.showToast({ title: '暂无可配置停车券', icon: 'none' })
    }
  },
  /**
   * 关闭弹窗
   */
  closeDialog(){
    this.setData({
      infoDialog: false
    })
  }
})